// import proFetch from "../../../../../public/functions/project-fetch";
import {hrAjax as ajax} from 'src/hrpub/common/utils/utils';
import updateButtonStatus from "./updateButtonStatus";
import {cacheTools, toast} from 'nc-lightapp-front';
import getMainTableData from "./getMainTableData";
import handleAllpks from "./handleAllpks";
import getOneAgreementInfo from "./getOneAgreementInfo";

export default function effectiveAgreementData() {
    const {effectivePks, agreementType, orgVal, pageFlag, editPk, json} = this.state;
    return ajax({
        url: '/nccloud/hrcm/agreement/ChangeEffectiveAction.do',
        body: {
            pk_agreements: effectivePks
        },
    }).then((res) => {
        if (res.success) {
            if (pageFlag === 'list') {
                getMainTableData.call(this);
            } else if (pageFlag === 'card') {
                let pks = effectivePks.toString();
                this.setState({
                    editPk: handleAllpks.getNextPk(editPk)
                }, () => {
                    handleAllpks.remove(pks); // 更新卡片分页主键
                    getOneAgreementInfo.call(this);
                    this.refs.header.setCardPaginationVisible(true, editPk);
                });
            }
            updateButtonStatus.call(this, orgVal, agreementType);
            toast({color: 'success', content: json['cm6011-000122']}); //生效成功
        }
    });
}
